<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="h" uri="/syzg-html"%>
<%
	request.setAttribute("ctx", request.getContextPath());
%>
<!DOCTYPE html>
<html>
<head>
<script src="${ctx}/zenithsun/plugins/ajaxfileupload.js" type="text/javascript"></script>
	<script type="text/javascript">
	  var NewsSelectModalUrl = "${ctx }/zenithsun/news/specialnews/selectNews.jsp";
	  var setNewsUrl = "${ctx }/path/specialnews/setNews";
	  function showSelectNewsModal(){
		  $("#myDlgSelectNews").load(NewsSelectModalUrl,function(){
			  $('#selectNewsModal').modal("show");
		  });
	  }
	  
	  $(function(){
		  $("#crop_upload").click(function () {
		        $.ajaxFileUpload
		        (
		            {
		                url: "${ctx}/path/newsinfo/uploadCover?newId=", //用于文件上传的服务器端请求地址
		                secureuri: false, //一般设置为false
		                fileElementId: 'crop_upload_file', //文件上传空间的id属性  <input type="file" id="file" name="file" />
		                dataType: 'json', //返回值类型 一般设置为json
		                success: function (data, status)  //服务器成功响应处理函数
		                {
		                	var coverPath = data.content;
	                        $("#coverImage").attr("src","${ctx}"+coverPath);
	                        $("#coverPath").val(data.content);
		                },
		                error: function (data, status, e)//服务器响应失败处理函数
		                {
		                	bootbox.alert("上传失败");
		                }
		            }
		        )
		   });
	  });
	</script>
</head>
<body>
<div class="modal fade bs-example-modal-lg" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-lg" role="document" style="margin-top: 0">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">新增专题新闻</h4>
      </div>
      <div class="modal-body" id="modalCore">
        <form class="form-horizontal" role="form" id="aeForm" name="aeForm">
          <fieldset>
            <input type="hidden" id="selectedNews" name="selectedNews" value="${selectedNews }"/>
        	<input type="hidden" id="selectedNewsName" name="selectedNewsName"/>
            <div class="bs-example bs-example-tabs" data-example-id="togglable-tabs">
			  <ul id="myTabs" class="nav nav-tabs" role="tablist">
			    <li role="presentation" class="active"><a href="#baseInfo" role="tab" data-toggle="tab">新闻基本信息</a></li>
			    <li role="presentation"><a href="#pics" role="tab" data-toggle="tab">新闻列表</a></li>
			  </ul>
			  <div id="myTabContent" class="tab-content" style="height: 420px;">
			    <div role="tabpanel" class="tab-pane fade in active" style="margin-top: 5px;" id="baseInfo" aria-labelledBy="home-tab">
				  <div class="form-group">
	              <label class="col-sm-2 control-label" for="title">专题标题</label>
	              <div class="col-sm-8">
	                <input type="text" id="title" name="title" value="" class="form-control" />
	              </div>
	            </div>
	            <div class="form-group">
	              <label class="col-sm-2 control-label" for="isTop">新闻设置</label>
	              <div class="col-sm-8">
	              	<label class="checkbox-inline">
	                	<input type="checkbox" id="isTop" name="isTop" value="0" onclick="this.value=this.checked?1:0"> 主题置顶
	                </label>
	              </div>
	            </div>
				  <div class="form-group">
	              <label class="col-sm-2 control-label" for="title">专题封面</label>
	              <div class="col-sm-8">
	                <input type="hidden" name="coverPath" id="coverPath" value="">
	              	<img width="100%" height="300" id="coverImage" src="${ctx}/zenithsun/news/mobile/images/Default-bg270x180.png">
	              </div>
	            </div>
				<div>
					<div style="float: right;">
						<input type="file" id="crop_upload_file" name="file" accept="image/*" />
					</div>
					<div style="float: right;">
						<button type="button" class="btn btn-primary" id="crop_upload">确认上传图片</button>
					</div>
				</div>
			    </div>
			    <div role="tabpanel" class="tab-pane fade" style="margin-top: 5px;" id="pics" aria-labelledBy="profile-tab">
			      <table width="100%" class="title" border="0" cellspacing="0" cellpadding="0">
					<tr>
					  <td align="right">
					    <h:permission module="xxx_xxx" operation="add">
					        <button type="button" class="btn btn-primary btn-sm" onclick="showSelectNewsModal()">添加新闻</button>
					      </h:permission>
					  </td>
					</tr>
				</table>
				<div id="newsList" style="overflow: auto;height:380px;"></div>
			    </div>
			  </div>
		    </div>
          </fieldset>
        </form>
      </div>
      <div id="myDlgSelectNews"></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary" onclick="submitSave('add');">保存</button>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
$('#aeForm').bootstrapValidator({
  message: 'This value is not valid',
  feedbackIcons: {
      valid: 'glyphicon glyphicon-ok',
      invalid: 'glyphicon glyphicon-remove',
      validating: 'glyphicon glyphicon-refresh'
  },
  fields: {
      /*name: {
    	  group: '.col-sm-3',
          message: 'The username is not valid',
          validators: {
              notEmpty: {
                  message: 'The username is required and cannot be empty'
              },
              stringLength: {
                  min: 6,
                  max: 30,
                  message: 'The username must be more than 6 and less than 30 characters long'
              }
          }
      },
      email: {
    	  group: '.col-sm-3',
          validators: {
              emailAddress: {
                  message: 'The input is not a valid email address'
              }
          }
      }*/
  	}
}).on('success.form.bv', function(e, data) {
	if($("#title").val() == "")
	{
		bootbox.alert("请选填写标题");
	}else{
		if($("#coverPath").val() == ""){
			
			bootbox.alert("请选择封面");
		}else{
			var records = new Array();
			var selectedNews = "";
            $("input:hidden[name='selectedNewsId']").each(function(){
                records.push($(this).val());
                selectedNews += $(this).val()+",";
            });
            selectedNews = selectedNews.substring(0, selectedNews.length-1);
			if(records.length <= 0){
				bootbox.alert("请选择新闻");
			}else{
				var url = "${ctx}/path/specialnews/addSpecialnews?selectedNews="+selectedNews;
				FormFunction.submitSave('add',url);
			}
		}
	}
});


</script>
</body>
</html>

